package com.ruoyi.mx.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mx.domain.MxComment;
import com.ruoyi.mx.service.IMxCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 美秀评论Controller
 *
 * @author ruoyi
 * @date 2021-10-12
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mx/comment" )
public class MxCommentController extends BaseController {

    private final IMxCommentService iMxCommentService;

    /**
     * 查询美秀评论列表
     */
    @PreAuthorize("@ss.hasPermi('mx:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(MxComment mxComment)
    {
        startPage();
        LambdaQueryWrapper<MxComment> lqw = new LambdaQueryWrapper<MxComment>();
        if (mxComment.getDeleted() != null){
            lqw.eq(MxComment::getDeleted ,mxComment.getDeleted());
        }
        if (StringUtils.isNotBlank(mxComment.getUid())){
            lqw.eq(MxComment::getUid ,mxComment.getUid());
        }
        if (StringUtils.isNotBlank(mxComment.getAid())){
            lqw.eq(MxComment::getAid ,mxComment.getAid());
        }
        if (StringUtils.isNotBlank(mxComment.getPid())){
            lqw.eq(MxComment::getPid ,mxComment.getPid());
        }
        if (mxComment.getLikes() != null){
            lqw.eq(MxComment::getLikes ,mxComment.getLikes());
        }
        if (mxComment.getUnlikes() != null){
            lqw.eq(MxComment::getUnlikes ,mxComment.getUnlikes());
        }
        if (mxComment.getReplies() != null){
            lqw.eq(MxComment::getReplies ,mxComment.getReplies());
        }
        if (StringUtils.isNotBlank(mxComment.getContent())){
            lqw.eq(MxComment::getContent ,mxComment.getContent());
        }
        if (mxComment.getIsread()!=null){
            lqw.eq(MxComment::getIsread ,mxComment.getIsread());
        }
        if (mxComment.getChecked()!=null){
            lqw.eq(MxComment::getChecked ,mxComment.getChecked());
        }
        List<MxComment> list = iMxCommentService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出美秀评论列表
     */
    @PreAuthorize("@ss.hasPermi('mx:comment:export')" )
    @Log(title = "美秀评论" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public R export(MxComment mxComment) {
        LambdaQueryWrapper<MxComment> lqw = new LambdaQueryWrapper<MxComment>(mxComment);
        List<MxComment> list = iMxCommentService.list(lqw);
        ExcelUtil<MxComment> util = new ExcelUtil<MxComment>(MxComment. class);
        return util.exportExcel(list, "comment" );
    }

    /**
     * 获取美秀评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('mx:comment:query')" )
    @GetMapping(value = "/{id}" )
    public R getInfo(@PathVariable("id" ) String id) {
        return R.success(iMxCommentService.getById(id));
    }

    /**
     * 新增美秀评论
     */
    @PreAuthorize("@ss.hasPermi('mx:comment:add')" )
    @Log(title = "美秀评论" , businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody MxComment mxComment) {
        return toAjax(iMxCommentService.save(mxComment) ? 1 : 0);
    }

    /**
     * 修改美秀评论
     */
    @PreAuthorize("@ss.hasPermi('mx:comment:edit')" )
    @Log(title = "美秀评论" , businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody MxComment mxComment) {
        return toAjax(iMxCommentService.updateById(mxComment) ? 1 : 0);
    }

    /**
     * 删除美秀评论
     */
    @PreAuthorize("@ss.hasPermi('mx:comment:remove')" )
    @Log(title = "美秀评论" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public R remove(@PathVariable String[] ids) {
        return toAjax(iMxCommentService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
